package com.woorigil.social.controller.admin;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.woorigil.social.Context;
import com.woorigil.social.controller.BaseController;
import com.woorigil.social.domain.subscribe.Mail;
import com.woorigil.social.domain.subscribe.MailDao;
import com.woorigil.social.domain.subscribe.ReadMail;

@Controller
public class MailReadController extends BaseController {
	@Autowired ReadMail readMail;
	@Autowired MailDao mailDao;
	
	@RequestMapping("/admin/mail/read")
	public ModelAndView read(String pw) throws Exception {
		if (!"1121".equals(pw)) {
			return null;
		}
		
		List<Mail> mails = readMail.execute();
		for (Mail mail : mails) {
			mailDao.insert(mail);
		}
		
		ModelAndView mav = new ModelAndView(getForwordPage("admin/mail/success"));
		mav.addObject("totalDealCount", Context.getTotalDealCount());
		mav.addObject("lastUpdatedAt", Context.getLastUpdatedAt());
		return mav;
	}	
}
